package io.gitee.cisumer.amazing.master;

import io.gitee.cisumer.amazing.Pixel;

import static java.lang.Math.log;

/**
 * @author gitee.com/cisumer
 * @date create in 2022/3/17
 */
public class MandelbrotDescartes implements Pixel {
	@Override
	public int r(int i, int j) {
		float x = 0, y = 0;
		int k;
		for (k = 0; k++ < 256; ) {
			float a = (float) (x * x - y * y + (i - 768.0) / 512);
			y = (float) (2 * x * y + (j - SIZE/2) / SIZE/2);
			x = a;
			if (x * x + y * y > 4) break;
		}
		return (int) (log(k) * 47);
	}
	
	@Override
	public int g(int i, int j) {
		float x=0,y=0;int k;for(k=0;k++<256;){float a= (float) (x*x-y*y+(i-768.0)/512);y= (float) (2*x*y+(j-512.0)/512);x=a;if(x*x+y*y>4)break;}return (int) (log(k)*47);
	}
	
	@Override
	public int b(int i, int j) {
		float x=0,y=0;int k;for(k=0;k++<256;){float a= (float) (x*x-y*y+(i-768.0)/512);y= (float) (2*x*y+(j-512.0)/512);x=a;if(x*x+y*y>4)break;}return (int) (128-log(k)*23);
	}
	
	@Override
	public String name() {
		return "笛卡尔心形函数";
	}
}
